<?php 
header("Pragma: public");
header("Expires: 0");
header("Accept-Ranges: bytes");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/vnd.ms-word");
header('Content-Disposition: attachment; filename=zachisl.xls');
header("Content-Transfer-Encoding: binary");

?>
<h2>
	<?php 
		echo 'факультет '.$facultets[$facultet_id].' '.$professions[$profession_id].' '.$learningforms[$learningform_id].' '.$learningtypes[$learningtype_id];
	?>
</h2>
  <h1>Зачисленные Общий рейтинг </h1>
  
    <table width="100%" cellspacing="2" cellpadding="0" border=1>
  <tr>
    <th><strong>id</strong></th>
    <th><strong>ФИО</strong></th>
    <th><strong>Выбранные специальности</strong></th>
    <th><strong>Оригинал документов</strong></th>
    <th><strong>Баллы по предметам</strong></th>   
    <th><strong>Баллы всего </strong></th>        
    <th><strong>Область</strong></th>
    <th><strong>Льготы или целевые</strong></th>
    <th><strong>Данные приоритета</strong></th>
  </tr>
  <?php 
  	while (list($key, $val) = each($plainrating_abiturients)) {
  		echo '<tr>';
  		$abiturient_id = $key;
  		foreach ($abiturients as $abiturient):
  		if ($abiturient['Abiturient']['id'] == $abiturient_id){
  			break;
  		}
  		endforeach;
  		echo '<td>';
  		echo $abiturient['Abiturient']['id'];
  		echo '</td>';
  		echo '<td>';
  		echo $abiturient['Abiturient']['lastname'].' ';
  		echo $abiturient['Abiturient']['firstname'].' ';
  		echo $abiturient['Abiturient']['surname'];
  		echo '</td>';
  		echo '<td>';
  		$tmp_selprof = array ();
  		foreach ($abiturient['Selectedprofession'] as $selectedprofession):
  		$tmp_selprof [$selectedprofession['id']] =  $selectedprofession;
  		endforeach;
  		sort($tmp_selprof);
  		$abiturient['Selectedprofession'] = $tmp_selprof;
  		foreach ($abiturient['Selectedprofession'] as $selectedprofession):
  		$resultedprofession ='';
  		switch ($selectedprofession['profession_id']){
  			case '1': $resultedprofession .='Л'; break;
  			case '2': $resultedprofession .='П'; break;
  			case '3': $resultedprofession .='СТ'; break;
  			case '4': $resultedprofession .='МПр'; break;
  			case '5': $resultedprofession .='Ф'; break;
  			case '6': $resultedprofession .='Э'; break;
  			case '7': $resultedprofession .='КлП'; break;
  			case '8': $resultedprofession .='СР'; break;
  			case '9': $resultedprofession .='БТ'; break;
  			case '10': $resultedprofession .='срЛ'; break;
  			case '11': $resultedprofession .='срС'; break;
  			case '12': $resultedprofession .='срЛД'; break;
  			case '13': $resultedprofession .='срФ'; break;
  			case '15': $resultedprofession .='М'; break;
  		}
  		switch ($selectedprofession['learningform_id']){
  			case '1': $resultedprofession .='О'; break;
  			case '2': $resultedprofession .='З'; break;
  			case '3': $resultedprofession .='Экст'; break;
  		}
  		switch ($selectedprofession['learningtype_id']){
  			case '1': $resultedprofession .='Б'; break;
  			case '2': $resultedprofession .='В'; break;
  		}
  		echo $resultedprofession.' ';  		
  		
  		endforeach;
  		echo '<td>';
  		if ($abiturient['Abiturient']['originaleducationdoc']){
  			echo '<font color=green>ДА</font>';
  		} else {
  			echo '<font color=red>НЕТ</font>';
  		}
  		// баллы по предметам
  		echo '<td>';
  		$total_score = 0;
  	
  		foreach ($subjects_ids as $subject_id):
  		echo $subjects[$subject_id];
  		if ($abiturient['Result'] == NULL){
  			echo ' ';
  		}
  		foreach ($abiturient['Result'] as $result):
  	  		if ($subject_id == $result['subject_id']){
  				$total_score += $result['score'];
  				echo ' - <font color=red>'.$result['score'].'</font> ';
  			}
  		endforeach;
  		endforeach;
  	//	echo '<font color="green">Всего - '.$total_score.'</font>';
  		echo '</td>';
  		echo '<td align=center>';
  		echo $val;
  		echo '</td>';
  		// телефоны абитуриета
  		echo '<td>';
  		echo $regions[$abiturient['Abiturient']['region_id']];
  		echo '</td>';
  		// вывод данных родственников
  		echo '<td>';
		if ($abiturient['Targetingintake']){
			echo 'область - <b>'.$regions[$abiturient['Targetingintake'][0]['region_id']].'</b> ';
			echo $tgintakeorgslist[$abiturient['Targetingintake'][0]['tgintakeorg_id']].' ';
			//echo '<br>';
		}
  	  	 if ($abiturient['Privilege']){
  			foreach ($abiturient['Privilege'] as $privilege):
  			echo $privilege['name'];
  			endforeach;}
  		echo '</td>';
  		// 
  		echo '<td>';
  		if ($abiturient['Prioritet']){
  			foreach ($abiturient['Prioritet'] as $prioritet):
  			echo $prioritet['name'];
  			endforeach;}
  		echo '</td>';
  		echo '</tr>';
  	} 	
  ?>
  </table>